package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysCalendar;
import com.ruoyi.system.service.SysCalendarService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author xmh
 * @version 1.0
 * @description: TODO
 * @date 2024/12/6 22:20
 */
@RestController
@RequestMapping("/system/calendar")
public class SysCalendarController extends BaseController {

    @Resource
    private SysCalendarService sysCalendarService;

    /**
     * 查询日程列表 分页
     */
    @GetMapping("/list")
    public TableDataInfo list(SysCalendar sysCalendar)
    {
        startPage();
        List<SysCalendar> list = sysCalendarService.selectSysCalendarList(sysCalendar);
        return getDataTable(list);
    }
    /**
     * 查询日程列表 不分页
     */
    @GetMapping("/no/page/list")
    public List<SysCalendar>  noPageList(SysCalendar sysCalendar)
    {
        List<SysCalendar> list = sysCalendarService.selectSysCalendarList(sysCalendar);
        return list;
    }

    /**
     * 导出日程列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCalendar sysCalendar)
    {
        List<SysCalendar> list = sysCalendarService.selectSysCalendarList(sysCalendar);
        ExcelUtil<SysCalendar> util = new ExcelUtil<SysCalendar>(SysCalendar.class);
        util.exportExcel(response, list, "日程");
    }

    /**
     * 获取日程详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(sysCalendarService.selectSysCalendarById(id));
    }

    /**
     * 新增日程
     */
    @PostMapping
    public AjaxResult add(@RequestBody SysCalendar sysCalendar)
    {
        return toAjax(sysCalendarService.insertSysCalendar(sysCalendar));
    }

    /**
     * 修改日程
     */
    @PutMapping
    public AjaxResult edit(@RequestBody SysCalendar sysCalendar)
    {
        return toAjax(sysCalendarService.updateSysCalendar(sysCalendar));
    }

    /**
     * 删除日程
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysCalendarService.deleteSysCalendarByIds(ids));
    }
}
